import request from '@/utils/request'

// 获取分类树结构
export function getCategoryTree() {
  return request({
    url: '/api/v1/products/categories/tree',
    method: 'get'
  })
}

// 获取所有分类
export function getAllCategories() {
  return request({
    url: '/api/v1/products/categories',
    method: 'get'
  })
}

// 分页获取分类
export function pageCategories(params) {
  return request({
    url: '/api/v1/products/categories/page',
    method: 'get',
    params
  })
}

// 获取指定分类
export function getCategory(id) {
  return request({
    url: `/api/v1/products/categories/${id}`,
    method: 'get'
  })
}

// 获取子分类
export function getChildCategories(parentId) {
  return request({
    url: `/api/v1/products/categories/children/${parentId}`,
    method: 'get'
  })
}

// 创建分类
export function createCategory(data) {
  return request({
    url: '/api/v1/products/categories',
    method: 'post',
    data
  })
}

// 更新分类
export function updateCategory(id, data) {
  return request({
    url: `/api/v1/products/categories/${id}`,
    method: 'put',
    data
  })
}

// 删除分类
export function deleteCategory(id) {
  return request({
    url: `/api/v1/products/categories/${id}`,
    method: 'delete'
  })
}

// 更新分类显示状态
export function updateCategoryVisible(categoryId, visible) {
  return request({
    url: `/api/v1/products/categories/${categoryId}/visible`,
    method: 'put',
    params: { visible }
  })
}

// 获取指定维度的分类
export function getCategoriesByDimension(dimension) {
  return request({
    url: `/api/v1/products/categories/dimension/${dimension}`,
    method: 'get'
  })
}

// 获取分类列表（可选父级ID）
export function getCategoryList(parentId) {
  return request({
    url: '/api/v1/products/categories/list',
    method: 'get',
    params: { parentId }
  })
}

// 获取分类商品列表
export function getCategoryProducts(categoryId, params) {
  return request({
    url: `/api/v1/products/categories/${categoryId}/products`,
    method: 'get',
    params
  })
}

// 获取多级分类筛选商品列表
export function getFilteredProducts(params) {
  return request({
    url: '/api/v1/products/categories/products/filter',
    method: 'get',
    params
  })
}
